﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestConstructor.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Tests.CMDenseMatrixTest
{
    #region Usings

    using System;

    using ExulLibrary.Exceptions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for the constructor of <see cref="CMDenseMatrix{T}"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.CMDenseMatrix{T}")]
    public sealed class TestConstructor
    {
        /// <summary>
        ///     Tests the constructor when data parameter is not <see langword="null"/> or empty and
        ///     have no <see langword="null"/> or empty elements.
        /// </summary>
        [Test]
        public void WhenDataParameterIsValid()
        {
            // Arrange
            var data = new[]
                       {
                           new object[1],
                           new object[1]
                       };

            // Act
            var matrix = new CMDenseMatrix<object>(data);

            // Assert
            Assert.That(matrix.RowsCount, Is.EqualTo(data[0].Length));
            Assert.That(matrix.ColumnsCount, Is.EqualTo(data.Length));
            Assert.That(matrix.IsSquare, Is.False);
            Assert.That(matrix.Values, Is.SameAs(data));
        }

        #if SAFE

        /// <summary>
        ///     Tests the constructor when data parameter is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenDataParameterIsNull()
        {
            // Act and Assert
            Assert.That(
                () => new CMDenseMatrix<object>(null),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("data"));
        }

        /// <summary>
        ///     Tests the constructor when data parameter is empty array.
        /// </summary>
        [Test]
        public void WhenDataParameterIsEmpty()
        {
            // Act and Assert
            Assert.That(
                () => new CMDenseMatrix<object>(new object[0][]),
                Throws.TypeOf<EmptyCollectionException>().With.Property("ParamName").EqualTo("data"));
        }

        /// <summary>
        ///     Tests the constructor when the first element of data parameter is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenDataParameterHasNullElement()
        {
            // Arrange
            var data = new[]
                       {
                           null,
                           new object[1]
                       };

            // Act and Assert
            Assert.That(
                () => new CMDenseMatrix<object>(data),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("data[0]"));
        }

        /// <summary>
        ///     Tests the constructor when the first element of data parameter is empty array.
        /// </summary>
        [Test]
        public void WhenDataParameterHasEmptyElement()
        {
            // Arrange
            var data = new[]
                       {
                           new object[0],
                           new object[1]
                       };

            // Act and Assert
            Assert.That(
                () => new CMDenseMatrix<object>(data),
                Throws.TypeOf<EmptyCollectionException>().With.Property("ParamName").EqualTo("data[0]"));
        }

        #endif
    }
}